<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>socket</title>
</head>
<body>
	<input type="text" id="username" />
	<button id="watchUser">监控这个用户名</button>
	<br>
	<button id="send">send</button>
	<script src="https://cdn.socket.io/socket.io-1.2.1.js"></script>
	<!-- <script type="text/javascript" src="/socket.io/socket.io.js"></script> -->
	<script type="text/javascript">
		var socket = io.connect('http://localhost:8000');
		socket.on('news',function(data){
		    //连接成功
		    console.log(data);
		    socket.emit('my other event',{my : 'data'});
		    console.log('link suucess')
		});
		socket.on('disconnect',function(data){
		    //连接断开
		    console.log('unlinked')
		});
		var btn = document.getElementById('watchUser');
		btn.onclick = function (event) {
		 var username = document.getElementById('username').value;
		 socket.on(username,function (data) {
		 	console.log( data);
		 });
		}
		// var sendBtn = document.getElementById('send');
		// sendBtn.onclick = function (event) {
		// 	var msg=document.getElementById('username').value;
		// 	socket.emit('201286250124',{msg:msg});
		// }
	</script>
</body>
</html>